import BaseView from '../BaseView';
import utils from '../../utils';

export default class ImageView extends BaseView {
    public src?: string;

    public async draw(ctx: CanvasRenderingContext2D) {
        const src = this.getSrc();
        if (!src) {
            return;
        }
        const image = await utils.loadImage(src);
        ctx.drawImage(image, 0, 0, image.width, image.height, this.getDrawX(), this.getDrawY(), this.getDrawWidth(), this.getDrawHeight());
        await super.draw(ctx);
    }

    public setSrc(src: string) {
        this.src = src;
    }

    public getSrc() {
        return this.src;
    }


}
